package genDoc;

import java.util.LinkedList;

import model.Room;
import model.User;

import org.jdom.Document;
import org.jdom.Element;

import command.CommandConstants;

public class FriendListDocGen {
	public static Document genDoc(Room room){
		Document doc = new Document();
		Element root = new Element(CommandConstants.CMD_UPDATE_FRIEND_LIST);
		doc.setRootElement(root);
		
		LinkedList<User> users = room.getLoggedUsers();
		for(User u : users){
			Element ele = new Element(CommandConstants.ELE_USER);
			ele.setAttribute(CommandConstants.ATTR_USER_NAME, u.getUserName());
			ele.setAttribute(CommandConstants.ATTR_IP, u.getIP());
			root.addContent(ele);
		}
		
		return doc;
	}
}
